package com.shxt.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shxt.model.ValidateLogin;
import com.shxt.pojo.D_User;
@WebServlet("/Login_Action")
public class Login_Action extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public Login_Action() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		ValidateLogin vl = new ValidateLogin();
		String username = new String(request.getParameter("username").getBytes("ISO8859-1"),"UTF-8");
		String password = new String(request.getParameter("password").getBytes("ISO8859-1"),"UTF-8");
		System.out.println(username+"========"+password);
		D_User user = new D_User();
		user = vl.validateUserLogin(username, password);
		if(user==null){
			System.out.println("NO PASS!");
		}else{
			request.getSession().setAttribute("username", user.getD_Username());
			request.getSession().setAttribute("userid", user.getD_UserId()+"");
			response.sendRedirect("netdisk.jsp");
		}
	}

}
